package datastream.api.datasource;

import org.apache.flink.streaming.api.datastream.DataStreamSink;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Socket {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 从 Socket 读取数据
        DataStreamSource<String> source = env.socketTextStream("localhost", 7000);

        // 转换数据
        SingleOutputStreamOperator<String> transformation = source.map(v -> v.split(" ")[0] + "只要第一个数据（以空格分割）");

        // 打印结果到控制台
        DataStreamSink<String> sink = transformation.print();
    }
}
